#include <stdio.h>
#include <stdlib.h>
#include <gmssl/sm3.h>

int main() {
    FILE *file = fopen("sn.txt", "rb");
    if (!file) {
        perror("Unable to open file");
        return EXIT_FAILURE;
    }

    SM3_CTX sm3_ctx;
    unsigned char hash[SM3_DIGEST_SIZE]; // 使用 SM3_DIGEST_SIZE

    sm3_init(&sm3_ctx); // 注意函数名小写

    unsigned char buffer[1024];
    size_t bytesRead;
    while ((bytesRead = fread(buffer, 1, sizeof(buffer), file)) > 0) {
        sm3_update(&sm3_ctx, buffer, bytesRead); // 注意函数名小写
    }

    sm3_finish(&sm3_ctx, hash); // 注意函数名小写
    fclose(file);

    printf("Hash value: ");
    for (int i = 0; i < SM3_DIGEST_SIZE; i++) { // 使用 SM3_DIGEST_SIZE
        printf("%02x", hash[i]);
    }
    printf("\n");

    return EXIT_SUCCESS;
}
